<?php

include_once "class_radcodes.php";

class rc_imobile {
	
  function set_display_mode($mode)
  {
    if (in_array($mode, array('standard','mobile','auto'))) {
      $session_object =& SESession::getInstance();
	  $session_object->set('imobile_display_mode', $mode);
    }
  }
  
  // static
  function get_display_mode()
  {
	$session_object =& SESession::getInstance();
	$display_mode = $session_object->get('imobile_display_mode','auto');
	if (!in_array($display_mode, array('standard','mobile','auto'))) {
	  $display_mode = 'auto';
	  $session_object->set('imobile_display_mode',$display_mode);
	}
	return $display_mode;
  }
  
  // static
  function is_webkit()
  {
    static $val;
    
    if ($val === null) {
      $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
      $regex = rc_toolkit::get_setting('imobile_user_agent');
      $val = preg_match($regex, $user_agent);
    }
    //$val = true;
    return $val;
  }
  
  // static
  function is_mobile_display()
  {
    $display_mode = rc_imobile::get_display_mode();
    $is_webkit = rc_imobile::is_webkit();
  	$is_mobile_display = ($is_webkit && $display_mode == 'auto') || $display_mode == 'mobile' ;
  	return $is_mobile_display;
  }
  
  function switchmode_enable()
  {
  	global $setting;
  	$is_webkit = rc_imobile::is_webkit();
  	return $setting['setting_imobile_switchmode'] == 2 || (rc_imobile::is_webkit() && $setting['setting_imobile_switchmode'] == 1);
  }
  
  function get_supported_plugin_menu()
  {
    $plugin_menu = array();
    $global_plugins =& SECore::getPlugins();
		foreach( $global_plugins as $plugin_type=>$plugin_info )
		{
		  if ($plugin_type == 'event') {
		    $plugin_menu[$plugin_type] = array(
		      'icon' => 'event_event48.gif',
		      'file' => 'browse_events.php',
		      'title' => 11340058
		    );
		  }
		  elseif ($plugin_type == 'group') {
        $plugin_menu[$plugin_type] = array(
          'icon' => 'group_group48.gif',
          'file' => 'browse_groups.php',
          'title' => 11340063
        );
		  }
		  elseif ($plugin_type == 'blog') {
        $plugin_menu[$plugin_type] = array(
          'icon' => 'blog_blog48.gif',
          'file' => 'browse_blogs.php',
          'title' => 11340065
        );
      }
		  elseif ($plugin_type == 'article') {
        $plugin_menu[$plugin_type] = array(
          'icon' => 'article48.gif',
          'file' => 'articles.php',
          'title' => 11340086
        );
      }
		  elseif ($plugin_type == 'business') {
        $plugin_menu[$plugin_type] = array(
          'icon' => 'business_business48.gif',
          'file' => 'browse_businesses.php',
          'title' => 11340088
        );
      }
		}
		
    return $plugin_menu;
  }
}

